home *** CD-ROM | disk | FTP | other *** search
- /*
- ** MAILER.C [edit EMAIL.H before compiling]
- **
- ** This program emails a specified message.
- */
-
- #define USE_SEE_DRIVER 1
-
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "see.h"
- #include "email.h"
-
- #define QUOTE 0x22
-
- static char Buffer[512];
-
- /* display error message */
-
- static void ErrorExit(int Code, LPSTR Msg)
- {printf("ERROR: ");
- if(Msg) printf("%s\n",Msg);
- if(Code)
- {seeErrorText(Code,(LPSTR)Buffer,50);
- printf("%s\n",(LPSTR)Buffer);
- exit(1);
- }
- }
-
- void main(int argc, char *argv[])
- {int Code;
- int Version;
- LPSTR Attach = NULL;
- ULONG TimeMark;
- long BytesSent;
- if((argc!=4)&&(argc!=5))
- {printf("Usage: MAILER email-text subject <email-addr>\n");
- printf("Usage: MAILER email-text subject <email-addr> {attach-file}\n");
- printf(" eg: MAILER %c@test.mai%c %cThis is a test%c %c<mike@marshallsoft.com>%c\n",
- QUOTE,QUOTE,QUOTE,QUOTE,QUOTE,QUOTE);
- exit(1);
- }
-
- /* display parameters */
-
- Version = seeStatistics(SEE_GET_VERSION);
- printf("SEE4C Version %1x.%1x.%1x\n",0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
- printf("Server : %s\n",(LPSTR)SMTP_HOST_NAME);
- printf(" From : %s\n",(LPSTR)YOUR_EMAIL_ADDR);
- if(*argv[1]=='@') printf(" File : %s\n", argv[1]);
- else printf(" Text : %c%s%c\n", QUOTE,argv[1],QUOTE);
- printf(" Subj : %s\n", argv[2]);
- printf(" To : %s\n", argv[3]);
- if(argc>4)
- {Attach = argv[4];
- printf(" Attach: %s\n", Attach);
- }
- /* check format of email addresses */
- Code = seeVerifyFormat((LPSTR)argv[3]);
- if(Code<0) ErrorExit(Code,(LPSTR)argv[3]);
- Code = seeVerifyFormat(YOUR_EMAIL_ADDR);
- if(Code<0) ErrorExit(Code,(LPSTR)YOUR_EMAIL_ADDR);
-
- /* define diagnostics log file */
- seeStringParam(SEE_LOG_FILE, (LPSTR)"mailer.log");
-
- /* connect to SMTP server */
- printf("Connecting to SMTP server %s\n", SMTP_HOST_NAME);
- Code = seeSmtpConnect(
- (LPSTR)SMTP_HOST_NAME, /* SMTP server */
- (LPSTR)YOUR_EMAIL_ADDR, /* return email address */
- (LPSTR)NULL); /* Reply-To header */
- if(Code<0)ErrorExit(Code,(LPSTR)"Connect:");
-
- /* turn off AUTO CALL driver */
- if(USE_SEE_DRIVER) seeIntegerParam(SEE_AUTO_CALL_DRIVER, 0);
-
- /* send email */
- Code = seeSendEmail(
- (LPSTR)argv[3], /* To list */
- (LPSTR)NULL, /* CC list */
- (LPSTR)NULL, /* BCC list */
- (LPSTR)argv[2], /* subject */
- (LPSTR)argv[1], /* message text */
- Attach); /* MIME attachment */
- if(Code<0) ErrorExit(Code,(LPSTR)"Sending email:");
-
- if(USE_SEE_DRIVER)
- {puts("Sending mail...");
- /* run the driver to send the email */
- TimeMark = GetCurrentTime() + 500; /* WIN32 API function */
- while(1)
- {Code = seeDriver();
- if((GetCurrentTime()>=TimeMark)||(Code==0))
- {TimeMark = GetCurrentTime() + 500;
- /* display progress */
- BytesSent = (long) seeStatistics(SEE_GET_TOTAL_BYTES_SENT);
- printf("%ld bytes written.\r",BytesSent);
- }
- if(Code==0) break;
- }
- printf("\n");
- /* turn AUTO CALL back on for seeClose */
- seeIntegerParam(SEE_AUTO_CALL_DRIVER, 1);
- }
-
- seeClose();
- } /* end main */
-
-
-